/**
 * API基础配置
 */

// API基础URL
export const API_BASE_URL = 'http://localhost:3001';

// 创建axios实例
const api = {
  baseURL: API_BASE_URL,
  headers: {
    'Content-Type': 'application/json',
  },
};

// 认证token管理
export const auth = {
  token: '',
  setToken(token: string) {
    this.token = token;
    localStorage.setItem('access_token', token);
  },
  getToken(): string {
    if (!this.token) {
      this.token = localStorage.getItem('access_token') || '';
    }
    return this.token;
  },
  clearToken() {
    this.token = '';
    localStorage.removeItem('access_token');
  },
};

// 获取认证头
export function getAuthHeaders(): Record<string, string> {
  const token = auth.getToken();
  return token ? { Authorization: `Bearer ${token}` } : {};
}

export default api;
